<template>
  <div id="app">
    <router-view/>
  </div>
</template>

<script>
export default {
  data() {
    return {
      timer: null
    }
  },
  methods: {
    createTimer() {
      this.timer = setInterval(() => {
        if (this.$route.path !== '/default')
          this.$router.push('/default')
      }, 5 * 60 * 1000)
    },
    goToScreensaver(val) {
      if (this.timer) {
        clearInterval(this.timer)
        this.timer = null
      }
      document.onclick = null
      if (val === null) {
        val = localStorage.getItem('screensaver') === '1'
      }
      if (val) {
        this.createTimer()
        document.onclick = () => {
          if (this.timer) {
            clearInterval(this.timer)
            this.timer = null
          }
          this.createTimer()
        }
      }
    }
  },
  computed: {
    screensaver() {
      return this.$store.state.screensaver
    }
  },
  watch: {
    screensaver(val) {
      this.goToScreensaver(val)
    }
  },
  mounted() {
    this.goToScreensaver(null)
  }
}
</script>

<style lang="scss">

</style>
